package com.cmft.waltzpagesample

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.cmft.waltzpagemanager.ContainerManager
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        mToTest1.setOnClickListener {
            ContainerManager.startPage(this, "1", "Test")
        }

        mToTest2.setOnClickListener {
            val bundle = Bundle()
            bundle.putString("TestParam", " App模块传递的参数... ")
            ContainerManager.startPage(this, "2", "Test", bundle)
        }

        initFragment()
    }

    private fun initFragment() {
        val bundle = Bundle()
        bundle.putString("TestFragmentParam", " App模块传递给Fragment的参数... ")
        val pageFragment = ContainerManager.getPageFragment("3", "Test", bundle)
        val ft = supportFragmentManager.beginTransaction()
        pageFragment?.let {
            ft.add(R.id.main_fl, it, "test")
            ft.show(it)
            ft.commitAllowingStateLoss()
        }
    }
}